package com.mengchengnet.chaperonage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mengchengnet.chaperonage.R;
import com.mengchengnet.chaperonage.domain.base.Chaperonage;
import com.mengchengnet.chaperonage.util.ViewUtil;
import com.mengchengnet.chaperonage.view.RatingBar;

import java.util.List;

/**
 * Created by Administrator on 16-2-22.
 */
public class ChaperonageAdapter extends ArrayAdapter<Chaperonage> {

    private static final String TAG = "ChaperonageAdapter";
    private Context mContext;
    private int resourceId;

    public ChaperonageAdapter(Context context, int resource, List<Chaperonage> objects) {
        super(context, resource, objects);
        resourceId = resource;
        mContext = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final Chaperonage chaperonage = getItem(position); // 获取当前项的实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);

        ImageView imageView = (ImageView) view.findViewById(R.id.iv_photo);
        ViewUtil.showImageView(mContext, imageView, chaperonage.getPhoto());

        TextView tvName = (TextView) view.findViewById(R.id.tv_name);
        tvName.setText(chaperonage.getName());

        RatingBar rbRating = (RatingBar) view.findViewById(R.id.rb_rating);
        rbRating.setStar(chaperonage.getRating());
        rbRating.setStarCount(0);

        TextView tvCommentsCount = (TextView) view.findViewById(R.id.tv_comments_count);
        tvCommentsCount.setText(chaperonage.getCommentsCount());

        TextView tvHometown = (TextView) view.findViewById(R.id.tv_hometown);
        tvHometown.setText(chaperonage.getHometown());

        TextView tvAge = (TextView) view.findViewById(R.id.tv_age);
        tvAge.setText(chaperonage.getAge());

        TextView tvWorkTime = (TextView) view.findViewById(R.id.tv_work_time);
        tvWorkTime.setText(chaperonage.getWorkTime());

        TextView tvDescription = (TextView) view.findViewById(R.id.tv_description);
        tvDescription.setText(chaperonage.getDescription());

        TextView tvPrice = (TextView) view.findViewById(R.id.tv_price);
        tvPrice.setText(chaperonage.getPrice());

        TextView tvDistance = (TextView) view.findViewById(R.id.tv_distance);
        if (chaperonage.getDistance().isEmpty()){
            tvDistance.setText("未知");
        }else {
            tvDistance.setText(chaperonage.getDistance()+"km");
        }


        return view;
    }
}
